<template>
  <div>
    <div>
      <el-button
          type="primary"
          @click="showAddReverse">添加讲座预定信息
      </el-button>
      <el-button
          type="primary"
          @click="showSearch">通过条件搜索
      </el-button>
      <!--      添加预定弹出对话框-->
      <el-dialog
          title="添加讲座"
          :visible.sync="dialogVisible"
          width="80%">
        <div>
          <el-row>
            <el-form  :model="addLectureReverse">
              <el-col :span="8">
                <el-form-item label="讲座编号:" prop="lectureId" style="margin-right: 10px">
                  <el-input v-model="addLectureReverse.lectureId" placeholder="请输入讲座编号"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="用户id:" prop="userId" style="margin-right: 10px">
                  <el-input v-model="addLectureReverse.userId" placeholder="请输入用户id"></el-input>
                </el-form-item>
              </el-col>
            </el-form>
          </el-row>
        </div>
        <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="doAddReverse">确 定</el-button>
  </span>
      </el-dialog>
<!--通过条件搜索-->
      <el-dialog
          title="根据条件搜索讲座预定信息"
          :visible.sync="dialogVisible2"
          width="80%">
        <div>
          <el-row>
            <el-form  :model="SearchInfo">
              <el-col :span="8">
                <el-form-item label="讲座预定编号:" prop="id" style="margin-right: 10px">
                  <el-input v-model="SearchInfo.id" placeholder="请输入讲座预定编号"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="讲座编号:" prop="lectureId" style="margin-right: 10px">
                  <el-input v-model="SearchInfo.lectureId" placeholder="请输入讲座编号"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="用户id:" prop="userId" style="margin-right: 10px">
                  <el-input v-model="SearchInfo.userId" placeholder="请输入用户id"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="讲座名称:" prop="name" style="margin-right: 10px">
                  <el-input v-model="SearchInfo.name" placeholder="请输入讲座名称"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="讲座地址:" prop="address" style="margin-right: 10px">
                  <el-input v-model="SearchInfo.address" placeholder="请输入讲座地址"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="剩余数量大于:" prop="remainNumbers" style="margin-right: 10px">
                  <el-input type="numbers" v-model="SearchInfo.remainNumbers" placeholder="请输入剩余数量"></el-input>
                </el-form-item>
              </el-col>
            </el-form>
          </el-row>
        </div>
        <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible2 = false">取 消</el-button>
    <el-button type="primary" @click="doSearch">确 定</el-button>
  </span>
      </el-dialog>
    </div>
    <!--  表格  -->
    <div style="margin-top: 10px">
      <el-table
          :data="lectureReverseInfo"
          border
          stripe
          style="width: 90%;margin-top: 20px;font-size: 15px"
          height="600">
        <!--          type="selection"-->
        <el-table-column
            width="55">
        </el-table-column>
        <el-table-column
            fixed="left"
            prop="id"
            label="预定编号"
            width="150">
        </el-table-column>
        <el-table-column
            fixed="left"
            prop="lectureId"
            label="讲座编号"
            width="150">
        </el-table-column>
        <el-table-column
            fixed="left"
            prop="userId"
            label="用户编号"
            width="150">
        </el-table-column>
        <el-table-column
            prop="lectureinfos[0].name"
            label="讲座名"
            width="120">
        </el-table-column>
        <el-table-column
            prop="lectureinfos[0].address"
            label="讲座地址"
            width="120">
        </el-table-column>
        <el-table-column
            prop="lectureinfos[0].totalNumbers"
            label="讲座座位总数"
            width="120">
        </el-table-column>
        <el-table-column
            prop="lectureinfos[0].remainNumbers"
            label="座位剩余数量"
            width="120">
        </el-table-column>
        <el-table-column
            prop="reverseDate"
            label="预定时间"
            width="120">
        </el-table-column>
        <el-table-column
            prop="lectureinfos[0].beginDate"
            label="讲座开始时间"
            width="120">
        </el-table-column>
        <el-table-column
            prop="lectureinfos[0].endDate"
            label="讲座结束时间"
            width="120">
        </el-table-column>
        <el-table-column
            fixed="right"
            label="操作"
            width="160">
          <template slot-scope="scope">
            <el-button

                size="mini"
                type="danger"
                @click="doDelete(scope.$index, scope.row)">删除
            </el-button>
            <el-button

                size="mini"
                type="primary"
                @click="showEditView(scope.row)">编辑
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-dialog
        title="修改讲座预定"
        :visible.sync="dialogVisible1"
        width="80%">
      <div>
        <el-row>
          <el-form  :model="lectureReverseInfo1">
            <el-col :span="8">
              <el-form-item label="讲座预定编号:" prop="id" style="margin-right: 10px">
                <el-input disabled v-model="lectureReverseInfo1.id" placeholder="请输入讲座预定编号"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="讲座编号:" prop="lectureId" style="margin-right: 10px">
                <el-input v-model="lectureReverseInfo1.lectureId" placeholder="请输入讲座编号"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="用户编号:" prop="userId" style="margin-right: 10px">
                <el-input v-model="lectureReverseInfo1.userId" placeholder="请输入用户编号"></el-input>
              </el-form-item>
            </el-col>

          </el-form>
        </el-row>
      </div>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible1 = false">取 消</el-button>
    <el-button type="primary" @click="changeReverse">确 定</el-button>
  </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "SystemLectureReverseManagement",
  data(){
    return{
      SearchInfo:{
        id: '',
        lectureId: '',
        userId: '',
        name: '',
        address: '',
        remainNumbers: '',
      },
      dialogVisible2:false,
      lectureReverseInfo1:[{
        id: '',
        lectureId: '',
        userId: '',
        reverseDate: '',
      }],
      dialogVisible1:false,
      dialogVisible:false,
      addLectureReverse:{
        id: '',
        lectureId: '',
        userId: '',
        reverseDate: '',
      },
      lectureReverseInfo:[{
        id: '',
        lectureId: '',
        userId: '',
        reverseDate: '',
        lectureinfos:{
          id:'',
          name: '',
          address: '',
          totalNumbers: '',
          remainNumbers: '',
          beginDat: '',
          endDate: '',
        },


      }],
      lectureinfos:{
        id:'',
        name: '',
        address: '',
        totalNumbers: '',
        remainNumbers: '',
        beginDat: '',
        endDate: '',
      },
    }
  },
  mounted() {//页面加载时就会初始化的数据
    this.initReverseInfo();
  },
  methods:{
    doSearch()
    {

      this.getRequest('/system/LectureReverseManagement/AddLectureReverse/listByid?' +
          'id='+ this.SearchInfo.id+
          '&lectureId='+ this.SearchInfo.lectureId+
          '&userId='+ this.SearchInfo.userId+
          '&lectureinfos%5B0%5D.remainNumbers='+ this.SearchInfo.remainNumbers+
          '&lectureinfos%5B0%5D.name='+ this.SearchInfo.name+
          '&lectureinfos%5B0%5D.address='+ this.SearchInfo.address
      ).then(resp=>{
        if (resp){
          this.lectureReverseInfo=resp;
          this.dialogVisible2=false;
        }
      })
    },
    showSearch(){
      this.dialogVisible2=true;
    },
    changeReverse()
    {

      //this.lectureReverseInfo1.reverseDate=new Date();
      this.putRequest('/system/LectureReverseManagement/update',this.lectureReverseInfo1).then(resp=>{
        if(resp)
        {
          this.initReverseInfo();
          this.dialogVisible1=false;
        }
      })
    },
    showEditView(data)
    {
      this.dialogVisible1=true;
      this.lectureReverseInfo1=data;

    },
    doDelete(index, data){
      this.$confirm("删除用户ID为["+data.lectureinfos[0].id +"]讲座名为["+ data.lectureinfos[0].name + "]的讲座的预定, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
          .then(() => {
            console.log(data);
            this.deleteRequest("/system/LectureReverseManagement/AddLectureReverse/delete?id="
                +this.lectureReverseInfo[index].id+"&lectureId="+this.lectureReverseInfo[index].lectureId).then((res) => {
              if (res) {
                this.initReverseInfo();
                this.dialogVisible=false;
              }
            });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消",
            });
          });
    },
    doAddReverse(){//添加预定信息,在发送请求前,把空字符串改为id 和名字
      this.addLectureReverse.id=0;
      this.postRequest('/system/LectureReverseManagement/AddLectureReverse/add',this.addLectureReverse).then(resp=>{
        if (resp)
        {
          this.initReverseInfo();
          this.dialogVisible=false;
        }
      })
    },
    showAddReverse(){
      this.dialogVisible = true;
    },
    initReverseInfo(){
console.log(this.lectureinfos)

      this.lectureinfos[1]='';
      this.lectureinfos[2]='';
      this.getRequest('/system/LectureReverseManagement/AddLectureReverse/listByid?' +
          'lectureinfos%5B0%5D.name='+ this.lectureinfos[1]+
          '&lectureinfos%5B0%5D.address='+ this.lectureinfos[2]
      ).then(resp=>{
        if (resp){
          this.lectureReverseInfo=resp;
        }
      })

    }
  }

}
</script>

<style scoped>

</style>